﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using System.IO;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;

namespace DotNetNuke.Tests.UI.WatiN.SiteTests
{
    [TestFixture]
    [DependsOn(typeof(PageTests))]
    [DependsOn(typeof(UserAccountsTests))]
    public class GeneralModuleTests : STBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {
            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Add_Text_Module_To_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            //Act
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML Pro");

                }
            }

            //Assert
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Test Module"));
            Assert.IsTrue(ieInstance.Div(Find.ById(s => s.EndsWith("HtmlModule_lblContent"))).Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Add_Text_Module_To_Page_Ontop_of_Module()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            string module1 = "First Module";
            string topModule = "Top Module";

            //Add a module then add second module
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(module1, "HTML");
                    System.Threading.Thread.Sleep(2000);
                    controlPanel.AddModuleToPageInsert(topModule, "HTML", "Top", "");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(module1, "HTML Pro");
                    System.Threading.Thread.Sleep(2000);
                    controlPanel.AddModuleToPageInsert(topModule, "HTML Pro", "Top", "");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(module1, "HTML");
                    System.Threading.Thread.Sleep(2000);
                    ribbonBar.AddHTMLModuleToPage(topModule, "HTML", "Same As Page", "Top");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(module1, "HTML Pro");
                    System.Threading.Thread.Sleep(2000);
                    ribbonBar.AddHTMLModuleToPage(topModule, "HTML Pro", "Same As Page", "Top");

                }
            }
            System.Threading.Thread.Sleep(3000);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsTrue(modulePage.ModuleTitleSpans[0].Text.Equals(topModule));
            Assert.IsTrue(modulePage.ModuleTitleSpans[1].Text.Equals(module1));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Add_Text_Module_To_Bottom_Of_Pane()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            string module1 = "First Module";
            string bottomModule = "Bottom Module";

            //Add a module then add second module
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(module1, "HTML");
                    System.Threading.Thread.Sleep(2000);
                    controlPanel.AddModuleToPageInsert(bottomModule, "HTML", "Bottom", "");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(module1, "HTML Pro");
                    System.Threading.Thread.Sleep(2000);
                    controlPanel.AddModuleToPageInsert(bottomModule, "HTML Pro", "Bottom", "");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(module1, "HTML");
                    System.Threading.Thread.Sleep(2000);
                    ribbonBar.AddHTMLModuleToPage(bottomModule, "HTML", "Same As Page", "Bottom");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(module1, "HTML Pro");
                    System.Threading.Thread.Sleep(2000);
                    ribbonBar.AddHTMLModuleToPage(bottomModule, "HTML Pro", "Same As Page", "Bottom");

                }
            }
            System.Threading.Thread.Sleep(3000);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsTrue(modulePage.ModuleTitleSpans[1].Text.Equals(bottomModule));
            Assert.IsTrue(modulePage.ModuleTitleSpans[0].Text.Equals(module1));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Add_Existing_Module_To_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page 1";
            string pageName2 = "Test Page 2";

            //Add a page with a module
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(2000);
            string moduleContent = "This is module content for testing.";
            string moduleName = "Test Module";
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Add another page
            System.Threading.Thread.Sleep(1000);
            if (usesRibbonBar)
            {
                ribbonBar.NewPageLink.Click();
            }
            else
            {
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName2, "None Specified");

            //Act
            ieInstance.GoTo(SiteURL + "/testpage2.aspx");
            System.Threading.Thread.Sleep(2500);
            if (usesRibbonBar)
            {
                ribbonBar.AddExistingModuleToPage(pageName, moduleName, "rcbHovered ");
            }
            else
            {
                controlPanel.AddExistingModuleToPage(pageName, moduleName);
            }
            System.Threading.Thread.Sleep(1000);

            //Assert
            SiteMenu menu = new SiteMenu(homePage);
            Assert.AreEqual(pageName2, menu.BreadCrumbSpan.Text);
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleContent));
            //Change the text on the copied module
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.AddContentToModule("Something new", 0);

            ieInstance.GoTo(SiteURL + "/testpage1.aspx");
            System.Threading.Thread.Sleep(1500);
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains(moduleContent));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Something new"));
            //Change the text on the original module
            modulePage.AddContentToModule("different text", 0);

            ieInstance.GoTo(SiteURL + "/testpage2.aspx");
            System.Threading.Thread.Sleep(1500);
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("Something new"));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("different text"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Move_Module_Up()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string moduleName;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            //Add three modules for testing 
            for (int i = 0; i < 3; i++)
            {
                moduleName = "Test Module " + i;
                if (!usesRibbonBar)
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML");
                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                    }
                }
                else
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                    }
                }
                System.Threading.Thread.Sleep(2000);
            }
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 2"));
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);

            //Act
            //actionMenu.GetActionMenuImageForModule(2).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPaneAndModuleNumber("Content", 2).FireEvent("onmouseover");
            actionMenu.MoveModuleUpLink.Click();

            //Assert
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 2"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 1"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Move_Module_Down()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string moduleName;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            //Add three modules for testing 
            for (int i = 0; i < 3; i++)
            {
                moduleName = "Test Module " + i;
                if (!usesRibbonBar)
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML");
                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                    }
                }
                else
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                    }
                }
                System.Threading.Thread.Sleep(2000);
            }
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 2"));
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);

            //Act
            //actionMenu.GetActionMenuImageForModule(0).FireEvent("onmouseover");
            //actionMenu.MoveActionMenuItem.FireEvent("onmouseover");
            actionMenu.MoveModuleDownLink.Click();

            //Assert
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 2"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Move_Module_Top()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string moduleName;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            //Add three modules for testing 
            for (int i = 0; i < 3; i++)
            {
                moduleName = "Test Module " + i;
                if (!usesRibbonBar)
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML");
                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                    }
                }
                else
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                    }
                }
                System.Threading.Thread.Sleep(2000);
            }
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 2"));
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);

            //Act
            //actionMenu.GetActionMenuImageForModule(2).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPaneAndModuleNumber("Content", 2).FireEvent("onmouseover");
            actionMenu.MoveModuleTopLink.Click();

            //Assert
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 2"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Move_Module_Bottom()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string moduleName;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");

            //Add three modules for testing 
            for (int i = 0; i < 3; i++)
            {
                moduleName = "Test Module " + i;
                if (!usesRibbonBar)
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML");
                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                    }
                }
                else
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                    }
                }
                System.Threading.Thread.Sleep(2000);
            }
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 2"));
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);

            //Act
            //actionMenu.GetActionMenuImageForModule(0).FireEvent("onmouseover");
            //actionMenu.MoveActionMenuItem.FireEvent("onmouseover");
            actionMenu.MoveModuleBottomLink.Click();

            //Assert
            Assert.IsTrue(homePage.GetAllModuleContainers()[2].InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[0].InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.GetAllModuleContainers()[1].InnerHtml.Contains("Test Module 2"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Move_Module_To_New_Pane()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string moduleName;
            string pageName = "Test Page";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            //Add two modules for testing 
            for (int i = 0; i < 2; i++)
            {
                moduleName = "Test Module " + i;
                if (!usesRibbonBar)
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML");
                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                    }
                }
                else
                {
                    if (VersionType.CompareTo("Community") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                    }
                    else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                    {
                        ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                    }
                }
                System.Threading.Thread.Sleep(2000);
            }

            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);
            //Act 
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module 0"));
            //actionMenu.GetActionMenuImageForModule(0).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPane("Content").FireEvent("onmouseover");
            actionMenu.MoveLeftPaneLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(homePage.LeftPaneCell.InnerHtml.Contains("Test Module 1"));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module 0"));

            ////Act
            //actionMenu.GetActionMenuImageForModuleInPane(homePage.LeftPaneCell.Id).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPane("Left").FireEvent("onmouseover");
            actionMenu.MoveRightPaneLink.Click();
            System.Threading.Thread.Sleep(2500);

            //Assert
            Assert.IsTrue(homePage.RightPaneCell.InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module 1"));
            System.Threading.Thread.Sleep(1000);

            //Act
            //actionMenu.GetActionMenuImageForModuleInPane(homePage.RightPaneCell.Id.ToString()).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPane("Right").FireEvent("onmouseover");
            actionMenu.MoveBottomPaneLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(homePage.BottomPaneDiv.InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module 1"));
            System.Threading.Thread.Sleep(1000);

            //Act
            //homePage.BottomPaneDiv.Image(Find.ById(s => s.Contains("dnnACTIONS_ctldnnACTIONSicn"))).FireEvent("onmouseover");
            //actionMenu.GetMoveActionMenuSpanForPane("Bottom").FireEvent("onmouseover");
            actionMenu.MoveTopPaneLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert
            Assert.IsTrue(homePage.TopPaneDiv.InnerHtml.Contains("Test Module 0"));
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module 1"));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_View_Permissions()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";

            //Add A User
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(1000);
            ieInstance.GoTo(SiteURL + "/Home.aspx");

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage("Test Module", "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage("Test Module", "HTML Pro");

                }
            }

            //Act 
            System.Threading.Thread.Sleep(1000);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.InheritPagePermissionsCheckBox.ClickNoWait();
            System.Threading.Thread.Sleep(500);
            modulePage.UpdateLink.ClickNoWait();

            //Assert 
            System.Threading.Thread.Sleep(1500);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(1500);
            loginPage.LogoffUser();
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            System.Threading.Thread.Sleep(1500);
            SiteMenu menu = new SiteMenu(homePage);
            Assert.IsTrue(menu.BreadCrumbSpan.Text.Equals(pageName));
            Assert.IsTrue(homePage.ContentPane.InnerHtml == null);
            Assert.IsFalse(homePage.ModuleMessageSpan.Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Display_On_All_Pages()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            string capturePath = CapturePath + @"\GeneralModuleTests\ModifyModule\";
            WatiNAssert watinAssert = new WatiNAssert(ieInstance, capturePath);
            if (!Directory.Exists(capturePath))
            {
                Directory.CreateDirectory(capturePath);
            }
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This module will be displayed on all pages";

            //Add A page 
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent("Test Module", "HTML Pro", moduleContent, 0);

                }
            }

            //Act 
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            System.Threading.Thread.Sleep(1500);
            //modulePage.AdvancedSettingsExpandButton.Click();
            modulePage.DisplayOnAllPagesCheckbox.Checked = true;
            System.Threading.Thread.Sleep(1500);
            modulePage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);

            //Assert 
            string[] pages = new string[] { "/Home.aspx", "/testpage.aspx", "/Admin.aspx", "/Admin/SiteSettings.aspx", "/Admin/Pages.aspx", "/Admin/Extensions.aspx",
                "/Admin/Skins.aspx", "/Admin/SecurityRoles.aspx", "/Admin/UserAccounts.aspx", "/Admin/Vendors.aspx", "/Admin/SiteLog.aspx", "/Admin/Newsletters.aspx",
                "/Admin/FileManager.aspx", "/Admin/RecycleBin.aspx", "/Admin/LogViewer.aspx", "/Admin/SiteWizard.aspx", "/Admin/GoogleAnalytics.aspx", "/Admin/Taxonomy.aspx",
                "/Admin/SearchEngineSiteMap.aspx"};
            foreach (string s in pages)
            {
                ieInstance.GoTo(SiteURL + s);
                System.Threading.Thread.Sleep(2000);
                watinAssert.AssertIsTrue(homePage.ContentPane.InnerHtml.Contains("Test Module"), "ModuleMissingOnPage"+s.Replace("/","")+".jpg",s);
                watinAssert.AssertIsTrue(homePage.ContentPane.InnerHtml.Contains(moduleContent), "ModuleContentMissingOnPage" + s.Replace("/", "") + ".jpg");
            }
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Start_Date_Future()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Start Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";
            DateTime date = DateTime.Now;
            int year = date.Year;
            year = year + 3;
            string dateString = date.Month + "/" + date.Day + "/" + year;

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).Click();
            System.Threading.Thread.Sleep(1500);
            //modulePage.AdvancedSettingsExpandButton.Click();
            modulePage.StartDateField.TypeText(dateString);
            System.Threading.Thread.Sleep(2500);
            modulePage.UpdateLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert 
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Module Effective - " + dateString));
            loginPage.LogoffUser();
            ieInstance.GoTo(SiteURL + "/startpage.aspx");
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains(moduleContent));
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("Module Effective - " + dateString));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Start_Date_Past()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Start Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";
            DateTime date = DateTime.Now;
            int year = date.Year;
            year = year - 3;
            string dateString = date.Month + "/" + date.Day + "/" + year;

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.AdvancedSettingsExpandButton.Click();
            modulePage.StartDateField.Value = dateString;
            modulePage.UpdateLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert 
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("Module Effective - " + dateString));
            loginPage.LogoffUser();
            ieInstance.GoTo(SiteURL + "/startpage.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("Module Effective - " + dateString));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_End_Date_Past()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "End Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";
            DateTime date = DateTime.Now;
            int year = date.Year;
            year = year - 3;
            string dateString = date.Month + "/" + date.Day + "/" + year;

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            //modulePage.AdvancedSettingsExpandButton.Click();
            modulePage.EndDateField.Value = dateString;
            modulePage.UpdateLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert 
            Assert.IsTrue(homePage.ContentPane.InnerHtml.Contains("Module Expired - " + dateString));
            loginPage.LogoffUser();
            ieInstance.GoTo(SiteURL + "/endpage.aspx");
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("Module Expired - " + dateString));
        }
        
        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_End_Date_Future()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "End Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";
            DateTime date = DateTime.Now;
            int year = date.Year;
            year = year + 3;
            string dateString = date.Month + "/" + date.Day + "/" + year;

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
           // modulePage.AdvancedSettingsExpandButton.Click();
            modulePage.EndDateField.Value = dateString;
            modulePage.UpdateLink.ClickNoWait();
            System.Threading.Thread.Sleep(2000);

            //Assert 
            Assert.IsFalse(homePage.ContentPane.InnerHtml.Contains("Module Expired - " + dateString));
            loginPage.LogoffUser();
            ieInstance.GoTo(SiteURL + "/endpage.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("Module Expired - " + dateString));
        }
        
        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Change_Container()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.PageSettingsTabLink.Click();
            modulePage.ModuleContainerSelectList.Select("DarkKnight - Aside");
            modulePage.UpdateLink.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.AreEqual("c_container c_head_blue", modulePage.ContainerDiv.ClassName);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Print_Syndicate()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Assert 
            System.Threading.Thread.Sleep(2500);
            ModulePage modulePage = new ModulePage(homePage);
            Assert.IsFalse(modulePage.PrintIcon.Exists);
            Assert.IsFalse(modulePage.SyndicateIcon.Exists);

            //Act
            System.Threading.Thread.Sleep(1500);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.PageSettingsTabLink.ClickNoWait();
            modulePage.PrintCheckBox.Checked = true;
            modulePage.SyndicateCheckBox.Checked = true;
            modulePage.UpdateLink.ClickNoWait();

            //Assert
            System.Threading.Thread.Sleep(2500);
            Assert.IsTrue(modulePage.SyndicateIcon.Exists);
            Assert.IsTrue(modulePage.PrintIcon.Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Modify_Module_Move_To_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName;
            
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add two pages
            for(int i = 0; i < 2; i++)
            {
                pageName = "Test Page " + i;
                if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
                {
                    ribbonBar = new RibbonBar(homePage);
                    ribbonBar.NewPageLink.Click();
                    usesRibbonBar = true;
                }
                else
                {
                    controlPanel = new ControlPanel(homePage);
                    controlPanel.AddPageLink.Click();
                }
                PageSettingsPage newPage = new PageSettingsPage(homePage);
                newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            }
            ieInstance.GoTo(SiteURL + "/testpage0.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act 
            System.Threading.Thread.Sleep(1500);
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            modulePage.PageSettingsTabLink.Click();
            //modulePage.PageSettingsAdvancedSettingsExpandIcon.Click();
            modulePage.MoveToPageSelectList.Select("Test Page 1");
            modulePage.UpdateLink.ClickNoWait();

            //Assert 
            System.Threading.Thread.Sleep(1500);
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/testpage1.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Delete_Module_Using_Module_Menu_One_Instance()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            System.Threading.Thread.Sleep(1500);
           // actionMenu.ModuleActionMenuImage.FireEventNoWait("onmouseover");
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                actionMenu.DeleteActionMenuItem.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            Assert.IsTrue(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Delete_Module_Using_Module_Menu_Two_Instances()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add two pages
            for (int i = 0; i < 2; i++)
            {
                pageName = "Test Page " + i;
                if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
                {
                    ribbonBar = new RibbonBar(homePage);
                    ribbonBar.NewPageLink.Click();
                    usesRibbonBar = true;
                }
                else
                {
                    controlPanel = new ControlPanel(homePage);
                    controlPanel.AddPageLink.Click();
                }
                PageSettingsPage newPage = new PageSettingsPage(homePage);
                newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            }
            ieInstance.GoTo(SiteURL + "/testpage0.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            ieInstance.GoTo(SiteURL + "/testpage1.aspx");
            System.Threading.Thread.Sleep(1000);
            if (usesRibbonBar)
            {
                ribbonBar.AddExistingModuleToPage("Test Page 0", moduleName, "rcbHovered ");
            }
            else
            {
                controlPanel.AddExistingModuleToPage("Test Page 0", moduleName);
            }
            System.Threading.Thread.Sleep(2000);

            //Act
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            //actionMenu.ModuleActionMenuImage.FireEvent("onmouseover");
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                actionMenu.DeleteActionMenuItem.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/testpage0.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            Assert.IsTrue(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
            Assert.IsFalse(recycleBin.ModulesRecycleBin.Option("Test Page 0 - " + moduleName).Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Delete_Module_Using_Settings_Page_One_Instance()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Act
            ModulePage modulePage = new ModulePage(homePage);
            System.Threading.Thread.Sleep(1500);
            modulePage.GetModuleSettingsImage(0).ClickNoWait();
            //ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            //using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            //{
            //    modulePage.DeleteLink.ClickNoWait();
            //    dialog.WaitUntilExists();
            //    dialog.OKButton.Click();
            //}
            modulePage.DeleteLink.ClickNoWait();
            modulePage.YesConfirmationButton.Click();
            System.Threading.Thread.Sleep(1500);

            //Assert 
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            Assert.IsTrue(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
        }


        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Delete_Module_Using_Settings_Page_Two_Instances()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add two pages
            for (int i = 0; i < 2; i++)
            {
                pageName = "Test Page " + i;
                if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
                {
                    ribbonBar = new RibbonBar(homePage);
                    ribbonBar.NewPageLink.Click();
                    usesRibbonBar = true;
                }
                else
                {
                    controlPanel = new ControlPanel(homePage);
                    controlPanel.AddPageLink.Click();
                }
                PageSettingsPage newPage = new PageSettingsPage(homePage);
                newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");
            }
            ieInstance.GoTo(SiteURL + "/testpage0.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            ieInstance.GoTo(SiteURL + "/testpage1.aspx");
            if (usesRibbonBar)
            {
                ribbonBar.AddExistingModuleToPage("Test Page 0", moduleName, "rcbHovered ");
            }
            else
            {
                controlPanel.AddExistingModuleToPage("Test Page 0", moduleName);
            }
            System.Threading.Thread.Sleep(2000);

            //Act
            ModulePage modulePage = new ModulePage(homePage);
            modulePage.GetModuleSettingsImage(0).Click();
            //ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            //using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            //{
            //    modulePage.DeleteLink.ClickNoWait();
            //    dialog.WaitUntilExists();
            //    dialog.OKButton.Click();
            //}
            modulePage.DeleteLink.ClickNoWait();
            modulePage.YesConfirmationButton.Click();
            System.Threading.Thread.Sleep(1500);


            //Assert 
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/testpage0.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            Assert.IsTrue(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
            Assert.IsFalse(recycleBin.ModulesRecycleBin.Option("Test Page 0 - " + moduleName).Exists);
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        [DependsOn("Delete_Module_Using_Module_Menu_One_Instance")]
        public void Restore_Module_One_Instance()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Now Delete the Module
            System.Threading.Thread.Sleep(1500);
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            //actionMenu.ModuleActionMenuImage.FireEventNoWait("onmouseover");
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                actionMenu.DeleteActionMenuItem.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }

            //Act 
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            recycleBin.ModulesRecycleBin.Select(pageName + " - " + moduleName);
            recycleBin.RestoreModuleLink.Click();

            //Assert 
            Assert.IsFalse(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
        }

        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        [DependsOn("Delete_Module_Using_Module_Menu_One_Instance")]
        public void Delete_Module_From_Recycle_Bin()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;
            string pageName = "Test Page";
            string moduleContent = "This is some module content.";
            string moduleName = "Test Module";

            //Add a page
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            newPage.AddPageSelectTemplateAllUsersView(pageName, "None Specified");

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML", moduleContent, 0);

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPageWithContent(moduleName, "HTML Pro", moduleContent, 0);

                }
            }

            //Now Delete the Module
            ModuleActionMenu actionMenu = new ModuleActionMenu(homePage);
            ConfirmDialogHandler dialog = new ConfirmDialogHandler();
            System.Threading.Thread.Sleep(2000);
            //actionMenu.ModuleActionMenuImage.FireEventNoWait("onmouseover");
            using (new UseDialogOnce(ieInstance.DialogWatcher, dialog))
            {
                actionMenu.DeleteActionMenuItem.ClickNoWait();
                dialog.WaitUntilExists();
                dialog.OKButton.Click();
            }

            //Act 
            RecycleBinPage recycleBin = new RecycleBinPage(homePage);
            ieInstance.GoTo(SiteURL + "/Admin/RecycleBin.aspx");
            recycleBin.ModulesRecycleBin.Select(pageName + " - " + moduleName);
            recycleBin.DeleteModuleLink.ClickNoWait();
            recycleBin.YesConfirmationButton.Click();

            //Assert 
            System.Threading.Thread.Sleep(2000);
            Assert.IsFalse(recycleBin.ModulesRecycleBin.Option(pageName + " - " + moduleName).Exists);
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
        }


        [Test]
        [DependsOn("Add_Text_Module_To_Page")]
        public void Add_New_Module_Title_And_Visibility()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            Boolean usesRibbonBar = false;

            //Add a User for testing
            ieInstance.GoTo(SiteURL + "/Admin/UserAccounts.aspx");
            UserPage userPage = new UserPage(homePage);
            userPage.AddUser(TestUsers.User1.UserName, TestUsers.User1.Password, TestUsers.User1.FirstName, TestUsers.User1.LastName, TestUsers.User1.EmailAddress, TestUsers.User1.DisplayName);
            System.Threading.Thread.Sleep(10000);
            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            ieInstance.GoTo(SiteURL + "/Home.aspx");
            System.Threading.Thread.Sleep(3000);
            String pageName = "Module Page";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }

            newPage.AddPageGiveUserViewPermissionSelectTemplate(pageName, TestUsers.User1.UserName, "None Specified");
            System.Threading.Thread.Sleep(4000);
            //Act
            //Add a module with no title and "Same as Page" visibility
            ieInstance.GoTo(SiteURL + "/modulepage.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageSelectVisibility("", "HTML", "Same as Page", "Unique Text", 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageSelectVisibility("", "HTML Pro", "Same as Page", "Unique Text", 0);
                }

            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHtmlModuleToPageSameAsPageVisibility("", "HTML", "Unique Text", 0);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHtmlModuleToPageSameAsPageVisibility("", "HTML Pro", "Unique Text", 0);

                }
            }

            //Add a module with a title and page editors only visibility
            ieInstance.GoTo(SiteURL + "/modulepage.aspx");
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddHTMLModuleToPageSelectVisibility("Visibility Module", "HTML", "Page Editors Only", "Unique Text", 1);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddHTMLModuleToPageSelectVisibility("Visibility Module", "HTML Pro", "Page Editors Only", "Unique Text", 1);
                }

            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHtmlModuleToPagePageEditorsOnlyVisibility("Visibility Module", "HTML", "Unique Text", 1);
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHtmlModuleToPagePageEditorsOnlyVisibility("Visibility Module", "HTML Pro", "Unique Text", 1);

                }
            }

            //Assert
            loginPage.LogoffUser();
            //View Modules as a user
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.User1.UserName, TestUsers.User1.Password);
            ieInstance.GoTo(SiteURL + "/modulepage.aspx");
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains("Visibility Module"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Text/HTML"));
            loginPage.LogoffUser();
            //View modules as an admin
            System.Threading.Thread.Sleep(1500);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ieInstance.GoTo(SiteURL + "/modulepage.aspx");
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Visibility Module"));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Text/HTML"));

        }


        #endregion
    }
}
